﻿// AAControlDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "AAControlDlg.h"
#include "afxdialogex.h"


// CAAControlDlg 对话框

IMPLEMENT_DYNAMIC(CAAControlDlg, CDialogEx)

CAAControlDlg::CAAControlDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_AA, pParent)
	, m_dAngleLimitSpec(0)
	, m_nUVTime(0)
	, m_nCapWaitTime(0)
	, m_nPeakDiff(0)
	, m_nPeakSpec(0)
	, m_dPixelSize(0)
	, m_nReturnStep(0)
	, m_nSearchZCnt(0)
	, m_dSearchZSiepDis_1(0)
	, m_dSearchZSpec_1(0)
	, m_dSearchZSiepDis_2(0)
	, m_dSearchZSpec_2(0)
	, m_nAAStepCnt(0)
	, m_dAAStepDis(0)
	, m_dOffsetZ(0)
	, m_bOpenOffset(FALSE)
	, m_bSaveTF(FALSE)
	, m_bAutoReturn(FALSE)
	, m_nStepWait(0)
	, m_dCenterPer(0)
	, m_dFieldSfrDiffSpec(0)
	, CalibrationLimit(0)
	, AngleLimitFlag(FALSE)
	, PosX0(0)
	, PosY0(0)
	, PosZ0(0)
	, PosXt0(0)
	, PosYt0(0)
	, PosZt0(0)
	, PosX1(0)
	, PosY1(0)
	, PosZ1(0)
	, PosXt1(0)
	, PosYt1(0)
	, PosZt1(0)
	, PosX2(0)
	, PosY2(0)
	, PosZ2(0)
	, PosXt2(0)
	, PosYt2(0)
	, PosZt2(0)
	, PosX3(0)
	, PosY3(0)
	, PosZ3(0)
	, PosXt3(0)
	, PosYt3(0)
	, PosZt3(0)
	, m_nSNCnt1(0)
	, m_nSNCnt0(0)
	, SearchZReturnFlag(FALSE)
	, SearchZReturnStep(0)
	, ZPosLimit(0)
	, PosNGZ(0)
	, m_nHomeOffsetX(0)
	, m_nHomeOffsetY(0)
	, m_nHomeOffsetZ(0)
	, PosTbx1(0)
	, PosTbx2(0)
	, PosTbx3(0)
	, PosTbx4(0)
	, is_HandleNG(FALSE)
{

}

CAAControlDlg::~CAAControlDlg()
{
}

void CAAControlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_FS_ANGLELIMIT, m_dAngleLimitSpec);
	DDX_Text(pDX, IDC_EDIT_UV_TIME, m_nUVTime);
	DDX_Text(pDX, IDC_EDIT_CAP_WAIT, m_nCapWaitTime);
	DDX_Text(pDX, IDC_EDIT_PEAK_DIFF, m_nPeakDiff);
	//DDX_Text(pDX, IDC_EDIT_PEAK_DIFF, m_nPeakDiffSpec);
	DDX_Text(pDX, IDC_EDIT_PEAK_MIN, m_nPeakSpec);
	DDX_Text(pDX, IDC_EDIT_PIXEL_SIZE, m_dPixelSize);
	DDX_Text(pDX, IDC_EDIT_RETURN_CNT, m_nReturnStep);
	DDX_Text(pDX, IDC_EDIT_SEARCHZ_CNT, m_nSearchZCnt);
	DDX_Text(pDX, IDC_EDIT_SEARCHZ_STEP1, m_dSearchZSiepDis_1);
	DDX_Text(pDX, IDC_EDIT_SEARCHZ_SPEC1, m_dSearchZSpec_1);
	DDX_Text(pDX, IDC_EDIT_SEARCHZ_STEP2, m_dSearchZSiepDis_2);
	DDX_Text(pDX, IDC_EDIT_SEARCHZ_SPEC2, m_dSearchZSpec_2);
	DDX_Text(pDX, IDC_EDIT_AA_CNT, m_nAAStepCnt);
	DDX_Text(pDX, IDC_EDIT_AA_STEP, m_dAAStepDis);
	DDX_Text(pDX, IDC_EDIT_Z_OFFSET, m_dOffsetZ);
	DDX_Check(pDX, IDC_CHECK_OFFSET, m_bOpenOffset);
	DDX_Check(pDX, IDC_SAVE_TF, m_bSaveTF);
	DDX_Check(pDX, IDC_AUTO_RT_PEAK, m_bAutoReturn);
	DDX_Text(pDX, IDC_EDIT_STEP_WAIT, m_nStepWait);
	DDX_Text(pDX, IDC_EDIT_CNETER_PER, m_dCenterPer);
	DDX_Text(pDX, IDC_EDIT_FIELD_SFRDIFF, m_dFieldSfrDiffSpec);
	DDX_Text(pDX, IDC_EDIT_FS_ANGLELIMIT2, CalibrationLimit);
	DDX_Check(pDX, IDC_AUTO_ANGLE_LIMIT, AngleLimitFlag);
	DDX_Text(pDX, IDC_EDIT_POS, PosX0);
	DDX_Text(pDX, IDC_EDIT_POS2, PosY0);
	DDX_Text(pDX, IDC_EDIT_POS3, PosZ0);
	DDX_Text(pDX, IDC_EDIT_POS4, PosXt0);
	DDX_Text(pDX, IDC_EDIT_POS5, PosYt0);
	DDX_Text(pDX, IDC_EDIT_POS6, PosZt0);
	DDX_Text(pDX, IDC_EDIT_POS7, PosX1);
	DDX_Text(pDX, IDC_EDIT_POS8, PosY1);
	DDX_Text(pDX, IDC_EDIT_POS9, PosZ1);
	DDX_Text(pDX, IDC_EDIT_POS10, PosXt1);
	DDX_Text(pDX, IDC_EDIT_POS11, PosYt1);
	DDX_Text(pDX, IDC_EDIT_POS12, PosZt1);
	DDX_Text(pDX, IDC_EDIT_POS13, PosX2);
	DDX_Text(pDX, IDC_EDIT_POS14, PosY2);
	DDX_Text(pDX, IDC_EDIT_POS15, PosZ2);
	DDX_Text(pDX, IDC_EDIT_POS16, PosXt2);
	DDX_Text(pDX, IDC_EDIT_POS17, PosYt2);
	DDX_Text(pDX, IDC_EDIT_POS18, PosZt2);
	DDX_Text(pDX, IDC_EDIT_POS19, PosX3);
	DDX_Text(pDX, IDC_EDIT_POS20, PosY3);
	DDX_Text(pDX, IDC_EDIT_POS21, PosZ3);
	DDX_Text(pDX, IDC_EDIT_POS22, PosXt3);
	DDX_Text(pDX, IDC_EDIT_POS23, PosYt3);
	DDX_Text(pDX, IDC_EDIT_POS24, PosZt3);
	DDX_Text(pDX, IDC_EDIT5, m_nSNCnt1);
	DDX_Text(pDX, IDC_EDIT_LENS_SN, m_nSNCnt0);
	DDX_Check(pDX, IDC_CHECK7, SearchZReturnFlag);
	DDX_Text(pDX, IDC_EDIT4, SearchZReturnStep);
	DDX_Text(pDX, IDC_EDIT_ZLIMIT, ZPosLimit);
	DDX_Text(pDX, IDC_EDIT_NGZPOS, PosNGZ);
	DDX_Text(pDX, IDC_EDIT_POS25, m_nHomeOffsetX);
	DDX_Text(pDX, IDC_EDIT_POS26, m_nHomeOffsetY);
	DDX_Text(pDX, IDC_EDIT_POS27, m_nHomeOffsetZ);
	DDX_Text(pDX, IDC_EDIT_POS28, PosTbx1);
	DDX_Text(pDX, IDC_EDIT_POS29, PosTbx2);
	DDX_Text(pDX, IDC_EDIT_POS30, PosTbx3);
	DDX_Text(pDX, IDC_EDIT_POS31, PosTbx4);
	DDX_Check(pDX, IDC_SAVE_TF2, is_HandleNG);
}


BEGIN_MESSAGE_MAP(CAAControlDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CAAControlDlg::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_SETP1, &CAAControlDlg::OnBnClickedButtonSetp1)
	ON_BN_CLICKED(IDC_BUTTON_SETP2, &CAAControlDlg::OnBnClickedButtonSetp2)
	ON_BN_CLICKED(IDC_BUTTON_SETP3, &CAAControlDlg::OnBnClickedButtonSetp3)
	ON_BN_CLICKED(IDC_BUTTON_SETP4, &CAAControlDlg::OnBnClickedButtonSetp4)
	ON_BN_CLICKED(IDC_BUTTON_SETP5, &CAAControlDlg::OnBnClickedButtonSetp5)
	ON_BN_CLICKED(IDC_BUTTON_SETP6, &CAAControlDlg::OnBnClickedButtonSetp6)
END_MESSAGE_MAP()


// CAAControlDlg 消息处理程序


BOOL CAAControlDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	ReadConfigIni();

	CWnd* ctrl = GetTopWindow();
	while (ctrl != NULL)
	{
		ctrl->EnableWindow(gSystemMgr.isAdmin ? TRUE : FALSE);
		ctrl = ctrl->GetNextWindow();
	}

	if (!gSystemMgr.isAdmin)
	{
		GetDlgItem(IDC_EDIT_POS)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS2)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS3)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS4)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS5)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS6)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS7)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS8)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS9)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS10)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS11)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS12)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS13)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS14)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS15)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS16)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS17)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS18)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS19)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS20)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS21)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS22)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS23)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS24)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS28)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS29)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS30)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_POS31)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_SETP1)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_SETP2)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_SETP3)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_SETP4)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_SAVE)->EnableWindow(TRUE);

	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CAAControlDlg::ReadConfigIni()
{
	CalibrationLimit = gSystemMgr.CalibrationLimit;
	AngleLimitFlag = gSystemMgr.AngleLimitFlag;
	m_dAngleLimitSpec = gSystemMgr.m_dAngleLimitSpec;
	m_nUVTime = gSystemMgr.m_nUVTime;
	m_nCapWaitTime = gSystemMgr.m_nCaptureWaitTime;
	m_nPeakDiff = gSystemMgr.m_nPeakDiff;
	m_nPeakSpec = gSystemMgr.m_nPeakMin;
	m_dPixelSize = gSystemMgr.m_dPixelSize;
	m_nReturnStep = gSystemMgr.m_nReturnStepCnt;
	m_nSearchZCnt = gSystemMgr.m_nSearchZStepMaxCnt;
	m_dSearchZSiepDis_1 = gSystemMgr.m_dSearchZStep_1;
	m_dSearchZSpec_1 = gSystemMgr.m_dSearchZSpec_1;
	m_dSearchZSiepDis_2 = gSystemMgr.m_dSearchZStep_2;
	m_dSearchZSpec_2 = gSystemMgr.m_dSearchZSpec_2;
	m_nAAStepCnt = gSystemMgr.m_nAAStepMaxCnt;
	m_dAAStepDis = gSystemMgr.m_dAAStep;
	m_dOffsetZ = gSystemMgr.m_dOffsetZ;
	m_bOpenOffset = gSystemMgr.m_bOffsetFlag;
	m_bSaveTF = gSystemMgr.m_bSaveTFCurve;

	m_bAutoReturn = gSystemMgr.m_bAutoReturn;

	m_nStepWait = gSystemMgr.m_nStepWait;

	m_dCenterPer = gSystemMgr.m_dCenterPer;
	m_dFieldSfrDiffSpec = gSystemMgr.m_dFieldSfrDiffSpec;

	PosX0 = gSystemMgr.PosX[0];
	PosY0 = gSystemMgr.PosY[0];
	PosZ0 = gSystemMgr.PosZ[0];
	PosX1 = gSystemMgr.PosX[1];
	PosY1 = gSystemMgr.PosY[1];
	PosZ1 = gSystemMgr.PosZ[1];
	PosXt0 = gSystemMgr.PosXt[0];
	PosYt0 = gSystemMgr.PosYt[0];
	PosZt0 = gSystemMgr.PosZt[0];
	PosXt1 = gSystemMgr.PosXt[1];
	PosYt1 = gSystemMgr.PosYt[1];
	PosZt1 = gSystemMgr.PosZt[1];

	PosX2 = gSystemMgr.PosX[2];
	PosY2 = gSystemMgr.PosY[2];
	PosZ2 = gSystemMgr.PosZ[2];
	PosX3 = gSystemMgr.PosX[3];
	PosY3 = gSystemMgr.PosY[3];
	PosZ3 = gSystemMgr.PosZ[3];
	PosXt2 = gSystemMgr.PosXt[2];
	PosYt2 = gSystemMgr.PosYt[2];
	PosZt2 = gSystemMgr.PosZt[2];
	PosXt3 = gSystemMgr.PosXt[3];
	PosYt3 = gSystemMgr.PosYt[3];
	PosZt3 = gSystemMgr.PosZt[3];

	PosTbx1 = gSystemMgr.PosTbx[0];
	PosTbx2 = gSystemMgr.PosTbx[1];
	PosTbx3 = gSystemMgr.PosTbx[2];
	PosTbx4 = gSystemMgr.PosTbx[3];
	PosNGZ = gSystemMgr.PosNGZ;

	m_nHomeOffsetX = gSystemMgr.m_nHomeOffsetX;
	m_nHomeOffsetY = gSystemMgr.m_nHomeOffsetY;
	m_nHomeOffsetZ = gSystemMgr.m_nHomeOffsetZ;
	m_nSNCnt0 = gSystemMgr.m_nSNCnt[0];
	m_nSNCnt1 = gSystemMgr.m_nSNCnt[1];

	SearchZReturnFlag = gSystemMgr.SearchZReturnFlag;
	SearchZReturnStep = gSystemMgr.SearchZReturnStep;

	ZPosLimit = gSystemMgr.ZPosLimit;

	is_HandleNG = gSystemMgr.is_HandleNG;



	UpdateData(FALSE);
}

void CAAControlDlg::SaveValueToConfig()
{
	CString cstr;

	UpdateData(TRUE);
	gSystemMgr.is_HandleNG = is_HandleNG;
	cstr.Format(L"%d", gSystemMgr.is_HandleNG);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"is_HandleNG", cstr);

	gSystemMgr.SearchZReturnFlag = SearchZReturnFlag;
	cstr.Format(L"%d", gSystemMgr.SearchZReturnFlag);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"SearchZReturnFlag", cstr);
	gSystemMgr.SearchZReturnStep = SearchZReturnStep;
	cstr.Format(L"%d", gSystemMgr.SearchZReturnStep);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"SearchZReturnStep", cstr);

	gSystemMgr.m_nSNCnt[0] = m_nSNCnt0;
	cstr.Format(L"%d", gSystemMgr.m_nSNCnt[0]);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nSNCnt[0]", cstr);
	gSystemMgr.m_nSNCnt[1] = m_nSNCnt1;
	cstr.Format(L"%d", gSystemMgr.m_nSNCnt[1]);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nSNCnt[1]", cstr);

	gSystemMgr.AngleLimitFlag = AngleLimitFlag;
	cstr.Format(L"%d", gSystemMgr.AngleLimitFlag);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"AngleLimitFlag", cstr);
	gSystemMgr.CalibrationLimit = CalibrationLimit;
	cstr.Format(L"%.3f", gSystemMgr.CalibrationLimit);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"CalibrationLimit", cstr);
	gSystemMgr.m_dAngleLimitSpec = m_dAngleLimitSpec;
	cstr.Format(L"%.3f", gSystemMgr.m_dAngleLimitSpec);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dAngleLimitSpec", cstr);
	gSystemMgr.m_nUVTime = m_nUVTime;
	cstr.Format(L"%d", gSystemMgr.m_nUVTime);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nUVTime", cstr);
	gSystemMgr.m_nCaptureWaitTime = m_nCapWaitTime;
	cstr.Format(L"%d", gSystemMgr.m_nCaptureWaitTime);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nCaptureWaitTime", cstr);
	gSystemMgr.m_nPeakDiff = m_nPeakDiff;
	cstr.Format(L"%d", gSystemMgr.m_nPeakDiff);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nPeakDiff", cstr);
	gSystemMgr.m_nPeakMin = m_nPeakSpec;
	cstr.Format(L"%d", gSystemMgr.m_nPeakMin);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nPeakMin", cstr);
	gSystemMgr.m_dPixelSize = m_dPixelSize;
	cstr.Format(L"%.4f", gSystemMgr.m_dPixelSize);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dPixelSize", cstr);
	gSystemMgr.m_nReturnStepCnt = m_nReturnStep;
	cstr.Format(L"%d", gSystemMgr.m_nReturnStepCnt);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nReturnStepCnt", cstr);
	gSystemMgr.m_nSearchZStepMaxCnt = m_nSearchZCnt;
	cstr.Format(L"%d", gSystemMgr.m_nSearchZStepMaxCnt);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nSearchZStepMaxCnt", cstr);
	gSystemMgr.m_dSearchZStep_1 = m_dSearchZSiepDis_1;
	cstr.Format(L"%.4f", gSystemMgr.m_dSearchZStep_1);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dSearchZStep_1", cstr);
	gSystemMgr.m_dSearchZSpec_1 = m_dSearchZSpec_1;
	cstr.Format(L"%.4f", gSystemMgr.m_dSearchZSpec_1);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dSearchZSpec_1", cstr);
	gSystemMgr.m_dSearchZStep_2 = m_dSearchZSiepDis_2;
	cstr.Format(L"%.4f", gSystemMgr.m_dSearchZStep_2);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dSearchZStep_2", cstr);
	gSystemMgr.m_dSearchZSpec_2 = m_dSearchZSpec_2;
	cstr.Format(L"%.4f", gSystemMgr.m_dSearchZSpec_2);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dSearchZSpec_2", cstr);
	gSystemMgr.m_nAAStepMaxCnt = m_nAAStepCnt;
	cstr.Format(L"%d", gSystemMgr.m_nAAStepMaxCnt);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nAAStepMaxCnt", cstr);
	gSystemMgr.m_dAAStep = m_dAAStepDis;
	cstr.Format(L"%.4f", gSystemMgr.m_dAAStep);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dAAStep", cstr);
	gSystemMgr.m_dOffsetZ = m_dOffsetZ;
	cstr.Format(L"%.4f", gSystemMgr.m_dOffsetZ);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dOffsetZ", cstr);
	gSystemMgr.m_bOffsetFlag = m_bOpenOffset;
	cstr.Format(L"%d", gSystemMgr.m_bOffsetFlag);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_bOffsetFlag", cstr);//gSystemMgr.m_bSaveTFCurve
	gSystemMgr.m_bAutoReturn = m_bAutoReturn;
	cstr.Format(L"%d", gSystemMgr.m_bAutoReturn);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_bAutoReturn", cstr);
	gSystemMgr.m_bSaveTFCurve = m_bSaveTF;
	cstr.Format(L"%d", gSystemMgr.m_bSaveTFCurve);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_bSaveTFCurve", cstr);

	gSystemMgr.m_nStepWait = m_nStepWait;
	cstr.Format(L"%d", gSystemMgr.m_nStepWait);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nStepWait", cstr);

	gSystemMgr.m_dCenterPer = m_dCenterPer;
	cstr.Format(L"%.4f", gSystemMgr.m_dCenterPer);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dCenterPer", cstr);
	gSystemMgr.m_dFieldSfrDiffSpec = m_dFieldSfrDiffSpec;
	cstr.Format(L"%.4f", gSystemMgr.m_dFieldSfrDiffSpec);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_dFieldSfrDiffSpec", cstr);


	gSystemMgr.PosX[0] = PosX0;
	gSystemMgr.PosY[0] = PosY0;
	gSystemMgr.PosZ[0] = PosZ0;
	gSystemMgr.PosX[1] = PosX1;
	gSystemMgr.PosY[1] = PosY1;
	gSystemMgr.PosZ[1] = PosZ1;
	gSystemMgr.PosXt[0] = PosXt0;
	gSystemMgr.PosYt[0] = PosYt0;
	gSystemMgr.PosZt[0] = PosZt0;
	gSystemMgr.PosXt[1] = PosXt1;
	gSystemMgr.PosYt[1] = PosYt1;
	gSystemMgr.PosZt[1] = PosZt1;

	gSystemMgr.PosX[2] = PosX2;
	gSystemMgr.PosY[2] = PosY2;
	gSystemMgr.PosZ[2] = PosZ2;
	gSystemMgr.PosX[3] = PosX3;
	gSystemMgr.PosY[3] = PosY3;
	gSystemMgr.PosZ[3] = PosZ3;
	gSystemMgr.PosXt[2] = PosXt2;
	gSystemMgr.PosYt[2] = PosYt2;
	gSystemMgr.PosZt[2] = PosZt2;
	gSystemMgr.PosXt[3] = PosXt3;
	gSystemMgr.PosYt[3] = PosYt3;
	gSystemMgr.PosZt[3] = PosZt3;

	gSystemMgr.PosTbx[0] = PosTbx1;
	gSystemMgr.PosTbx[1] = PosTbx2;
	gSystemMgr.PosTbx[2] = PosTbx3;
	gSystemMgr.PosTbx[3] = PosTbx4;
	gSystemMgr.PosNGZ = PosNGZ;
	gSystemMgr.m_nHomeOffsetX = m_nHomeOffsetX;
	gSystemMgr.m_nHomeOffsetY = m_nHomeOffsetY;
	gSystemMgr.m_nHomeOffsetZ = m_nHomeOffsetZ;

	cstr.Format(L"%d", gSystemMgr.PosX[0]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosX[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosY[0]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosY[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZ[0]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZ[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosX[1]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosX[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosY[1]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosY[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZ[1]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZ[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosXt[0]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosXt[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosYt[0]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosYt[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZt[0]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZt[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosXt[1]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosXt[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosYt[1]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosYt[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZt[1]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZt[1]", cstr);

	cstr.Format(L"%d", gSystemMgr.PosX[2]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosX[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosY[2]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosY[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZ[2]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZ[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosX[3]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosX[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosY[3]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosY[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZ[3]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZ[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosXt[2]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosXt[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosYt[2]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosYt[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZt[2]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZt[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosXt[3]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosXt[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosYt[3]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosYt[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosZt[3]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosZt[3]", cstr);

	cstr.Format(L"%d", gSystemMgr.PosTbx[0]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosTbx[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosTbx[1]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosTbx[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosTbx[2]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosTbx[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosTbx[3]); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosTbx[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.PosNGZ); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"PosNGZ", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nHomeOffsetX); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nHomeOffsetX", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nHomeOffsetY); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nHomeOffsetY", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nHomeOffsetZ); gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"m_nHomeOffsetZ", cstr);
	gSystemMgr.ZPosLimit = ZPosLimit;
	cstr.Format(L"%d", gSystemMgr.ZPosLimit);
	gSystemMgr.m_cAAConfigIni.SaveConfigIni(L"AA", L"ZPosLimit", cstr);

	gSystemLog.DisplayLogAndSave(L"AA参数修改后：", LV_ERROR);

}

void CAAControlDlg::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类

	CDialogEx::OnCancel();
}


void CAAControlDlg::OnBnClickedButtonSave()
{
	SaveValueToConfig();
}


void CAAControlDlg::OnBnClickedButtonSetp1()
{
	//设定夹取镜头位置
	if (IDYES == AfxMessageBox(L"确定 设定当前位置为夹取镜头位置 吗？", MB_YESNO))
	{
		PosX0 = gSystemMgr.m_vCMotor[MOTOR_X].m_nCurPositon;
		PosY0 = gSystemMgr.m_vCMotor[MOTOR_Y].m_nCurPositon;
		PosZ0 = gSystemMgr.m_vCMotor[MOTOR_Z].m_nCurPositon;
		PosXt0 = gSystemMgr.m_vCMotor[MOTOR_Xt].m_nCurPositon;
		PosYt0 = gSystemMgr.m_vCMotor[MOTOR_Yt].m_nCurPositon;
		PosZt0 = gSystemMgr.m_vCMotor[MOTOR_Zt].m_nCurPositon;
		PosTbx1 = gSystemMgr.m_vCMotor[Table_X].m_nCurPositon;
		gSystemLog.DisplayLogAndSave(L"夹取镜头位置设置完成", LV_EVENT);
		UpdateData(FALSE);
	}
}


void CAAControlDlg::OnBnClickedButtonSetp2()
{
	//设定镜头上方位置
	if (IDYES == AfxMessageBox(L"确定 设定当前位置为镜头上方位置 吗？", MB_YESNO))
	{
		PosX1 = gSystemMgr.m_vCMotor[MOTOR_X].m_nCurPositon;
		PosY1 = gSystemMgr.m_vCMotor[MOTOR_Y].m_nCurPositon;
		PosZ1 = gSystemMgr.m_vCMotor[MOTOR_Z].m_nCurPositon;
		PosXt1 = gSystemMgr.m_vCMotor[MOTOR_Xt].m_nCurPositon;
		PosYt1 = gSystemMgr.m_vCMotor[MOTOR_Yt].m_nCurPositon;
		PosZt1 = gSystemMgr.m_vCMotor[MOTOR_Zt].m_nCurPositon;
		PosTbx2 = gSystemMgr.m_vCMotor[Table_X].m_nCurPositon;

		gSystemLog.DisplayLogAndSave(L"镜头上方位置设置完成", LV_EVENT);
		UpdateData(FALSE);
	}
}


void CAAControlDlg::OnBnClickedButtonSetp3()
{
	//设定AA开始位置
	if (IDYES == AfxMessageBox(L"确定 设定当前位置为AA开始位置 吗？", MB_YESNO))
	{
		PosX2 = gSystemMgr.m_vCMotor[MOTOR_X].m_nCurPositon;
		PosY2 = gSystemMgr.m_vCMotor[MOTOR_Y].m_nCurPositon;
		PosZ2 = gSystemMgr.m_vCMotor[MOTOR_Z].m_nCurPositon;
		PosXt2 = gSystemMgr.m_vCMotor[MOTOR_Xt].m_nCurPositon;
		PosYt2 = gSystemMgr.m_vCMotor[MOTOR_Yt].m_nCurPositon;
		PosZt2 = gSystemMgr.m_vCMotor[MOTOR_Zt].m_nCurPositon;
		PosTbx3 = gSystemMgr.m_vCMotor[Table_X].m_nCurPositon;

		gSystemLog.DisplayLogAndSave(L"AA开始位置设置完成", LV_EVENT);

		UpdateData(FALSE);
	}
}


void CAAControlDlg::OnBnClickedButtonSetp4()
{
	//设定AA上方位置
	if (IDYES == AfxMessageBox(L"确定 设定当前位置为AA上方位置 吗？", MB_YESNO))
	{
		PosX3 = gSystemMgr.m_vCMotor[MOTOR_X].m_nCurPositon;
		PosY3 = gSystemMgr.m_vCMotor[MOTOR_Y].m_nCurPositon;
		PosZ3 = gSystemMgr.m_vCMotor[MOTOR_Z].m_nCurPositon;
		PosXt3 = gSystemMgr.m_vCMotor[MOTOR_Xt].m_nCurPositon;
		PosYt3 = gSystemMgr.m_vCMotor[MOTOR_Yt].m_nCurPositon;
		PosZt3 = gSystemMgr.m_vCMotor[MOTOR_Zt].m_nCurPositon;
		PosTbx4 = gSystemMgr.m_vCMotor[Table_X].m_nCurPositon;

		gSystemLog.DisplayLogAndSave(L"AA上方位置设置完成", LV_EVENT);

		UpdateData(FALSE);
	}
}


void CAAControlDlg::OnBnClickedButtonSetp5()
{
	//设定AANG返回高度
	if (IDYES == AfxMessageBox(L"确定 设定当前位置为AA NG返回位置 吗？", MB_YESNO))
	{
		PosNGZ = gSystemMgr.m_vCMotor[MOTOR_Z].m_nCurPositon;
		/*PosXt3 = gSystemMgr.m_vCMotor[MOTOR_Xt].m_nCurPositon;
		PosYt3 = gSystemMgr.m_vCMotor[MOTOR_Yt].m_nCurPositon;
		PosZt3 = gSystemMgr.m_vCMotor[MOTOR_Zt].m_nCurPositon;*/
		gSystemLog.DisplayLogAndSave(L"AA NG返回位置设置完成", LV_EVENT);

		UpdateData(FALSE);
	}
}


void CAAControlDlg::OnBnClickedButtonSetp6()
{
	// TODO: 在此添加控件通知处理程序代码
	if (IDYES == AfxMessageBox(L"确定 设定当前位置为HomeOffset位置 吗？", MB_YESNO))
	{
		m_nHomeOffsetX = gSystemMgr.m_vCMotor[MOTOR_X].m_nCurPositon;
		m_nHomeOffsetY = gSystemMgr.m_vCMotor[MOTOR_Y].m_nCurPositon;
		m_nHomeOffsetZ = gSystemMgr.m_vCMotor[MOTOR_Z].m_nCurPositon;
		gSystemLog.DisplayLogAndSave(L"HomeOffset位置设置完成", LV_EVENT);

		UpdateData(FALSE);
	}


}
